'''
An example of a simple real Twisted application.

@author: Hatem Oraby
'''
from twisted.internet import selectreactor
selectreactor.install()
from twisted.internet import reactor, protocol
import time

print "My Name is: " + str(__name__) + " and the time is: " + str(time.asctime())


class EchoClient(protocol.Protocol):
    """Once connected, send a message, then print the result."""
    
    def connectionMade(self):
        #value = raw_input("Enter a string: ")
        value = "Helloooo"""
        self.transport.write(value)
    
    def dataReceived(self, data):
        "As soon as any data is received, write it back."
        print "Server said:", data
        self.transport.loseConnection()
    
    def connectionLost(self, reason):
        print "connection lost"

class EchoFactory(protocol.ClientFactory):
    protocol = EchoClient

    def clientConnectionFailed(self, connector, reason):
        print "Connection failed - goodbye!"
        reactor.stop()
    
    def clientConnectionLost(self, connector, reason):
        print "Connection lost - goodbye!"
        reactor.stop()




if __name__ == '__main__':
    f = EchoFactory()
    reactor.connectTCP('176.10.0.1', 8000, f)
    reactor.run()
    